window.uam = window.uam || {};
uam.cookieHandle = {
		callTask:function(params, success){
			
			if(typeof(microstrategy) != 'undefined'){
				var session = String(microstrategy.sessionState);
			}
			
			params = params || {};
			
			params["taskId"] = params["taskId"] || 'UserProfileService';
			params["taskEnv"] = params["taskEnv"] || 'xhr';
	        params["taskContentType"] = params["taskContentType"] || 'json';
	        params["session"] = params["session"] || String(session);
	        
	        success = success || function(data){ console ? console.log("callTask.data = " + data) : alert("callTask.data = " + data); }
			
	        console.log(params);
	        
			taskUrl = './taskProc';
			$.ajax({
				url:  taskUrl,
				type: 'GET',
				data: params,
				cache: "false",
				dataType: "text",
				async: true, //set to false in case we want it to wait
				success: success ,
				error: function (XMLHttpRequest, textStatus, errorThrown) {
			        alert("XMLHttpRequest="+XMLHttpRequest.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
			    } 
			});
		}
};

$(document).ready(function(){
	
	var cookieValue = {
		"predepartmentId":"predepartmentId",
		"mstrAType":"mstrAType3",
		"mstrPS":"mstrPS",
		"amexWebID":"amexWebID",
		"disabledPreFN":"disabledPreFN",
		"predepartmentDesc":"predepartmentDesc",
		"busnUC":"busnUC",
		"busnUD":"busnUD",
		"amexUC":"amexUC",
		"amexUDesc":"amexUDesc",
		"excpEC":"excpEC",
		"costCenter":"costCenter",
		"disabledPreMN":"disabledPreMN",
		"disabledPreLN":"disabledPreLN",
		"preempContID":"preempContID",
		"sndFunc":"sndFunc",
		"funcGroup":"funcGroup",
		"prephone":"0123456789",
		"preemail":"mstr@gmail.com",
		"prefirstname":"prefirstname",
		"premIn":"premIn",
		"prelastname":"prelastname",
		"prememail":"prememail",
		"preVPName":"preVPName",
		"prereason":"prereason",
		"prestatus":"prestatus",
		"prestatusDate":"prestatusDate"
	}
	
	//create cookies, and assign the value in cookies to UI
	$.each(cookieValue, function(i, val){
		//alert(cookieValue[i]);
		if($.cookie(i)==null || $.cookie(i)=="" || $.cookie(i)==" "){
			//alert("cookie null");
			$.cookie(i, cookieValue[i], {expires:10});
		}
		$("#"+i).val($.cookie(i));
	});
	
	//define a ajax call
	/*uam.cookieHandle.callTask({'up_code':104}, function(data){
		console.log(data);
		eval("var responseData = " + data);
		
		if(responseData["status"] = uam.Utils.responseCode.OK){
			alert("successfully get data from task");
		}
	});*/
});